package com.piotrs10.bsk.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.piotrs10.bsk.model.Faktura;
import com.piotrs10.bsk.model.TypKlienta;

public class TypKlientaDao extends BaseDao {
	public ArrayList<TypKlienta> getAll() {
		Connection connection = this.getConnection();
		PreparedStatement statement = null;
		ArrayList<TypKlienta> list = null;
		try {
			statement = connection.prepareStatement("SELECT id, nazwa FROM typ_klienta;");
			ResultSet set = statement.executeQuery();
			list = new ArrayList<TypKlienta>();
			while(set.next()) {
				list.add(new TypKlienta(set.getInt(1), set.getString(2)));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if(statement != null) {
				try {
					statement.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return list;
	}
}
